<%--
  Created by IntelliJ IDEA.
  User: 桔子
  Date: 2018/4/8
  Time: 20:38
  To change this template use File | Settings | File Templates.
--%>
<%@ page import="java.sql.*" %>
<%--
  Created by IntelliJ IDEA.
  User: 桔子
  Date: 2018/4/8
  Time: 19:27
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>登录验证</title>
</head>
<body>
<%!
    public static final String DBDRIVER="com.mysql.jdbc.Driver";
    public static final String DBURL="jdbc:mysql://youpaiyun.juzibiji.top:3306/test?useSSL=false";
    public static final String DBUSER="juzi";
    public static final String DBPASSWORD="jqsmx1731815301";
%>
<%
    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    boolean flag=false;
    String name = null;
%>
<%
    try{
        Class.forName(DBDRIVER);
        con=DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD);
        String sql = "select name from user where userid=? and password =?";
        pstmt=con.prepareStatement(sql);
        pstmt.setString(1,request.getParameter("id"));
        pstmt.setString(2,request.getParameter("password"));
        rs = pstmt.executeQuery();
        if(rs.next()){
            name = rs.getString(1);
            flag =true;
        }
    }catch(Exception e){
        System.out.println(e);
    }finally {
        try{
            rs.close();
            pstmt.close();
            con.close();
        }catch (Exception e){
            System.out.println(e);
        }
    }
%>
<%
    if (flag){
%>

<jsp:forward page="login_success.jsp">
    <jsp:param name="uname" value="<%=name%>"/>
</jsp:forward>
<%
}else{
%>
<jsp:forward page="login_failure.jsp"/>
<%
    }
%>
</body>
</html>
